MODULE_NAME := examples
ALL_SUB_DIRS := examples src/infra/log src/infra/system src/infra/utils src/protocol/alcs src/protocol/coap src/protocol/http src/protocol/http2 src/protocol/mqtt src/ref-impl/hal src/ref-impl/tls src/sdk-impl src/services/file_upload src/services/linkkit/cm src/services/linkkit/dm src/services/shadow src/services/subdev src/services/uOTA src/tools/linkkit_tsl_convert tests
AR := ar
CC := gcc
CFLAGS := -D_IS_LINKKIT_ --coverage -DALCS_ENABLED -DCMP_VIA_MQTT_DIRECT -DCM_ENABLED -DCM_SUPPORT_LOCAL_CONN -DCM_VIA_CLOUD_CONN -DCM_VIA_CLOUD_CONN_MQTT -DCOAP_OBSERVE_CLIENT_SUPPORTED -DCOAP_OBSERVE_SERVER_SUPPORTED -DCOAP_SERV_MULTITHREAD -DCOAP_USE_PLATFORM_LOG -DCOAP_USE_PLATFORM_MEMORY -DCONFIG_DM_DEVTYPE_SINGLE -DCONFIG_DM_SUPPORT_LOCAL_CONN -DCONFIG_GUIDER_AUTH_TIMEOUT=500 -DCONFIG_HTTP_AUTH_TIMEOUT=500 -DCONFIG_MBEDTLS_DEBUG_LEVEL=0 -DCONFIG_MID_HTTP_TIMEOUT=500 -DCONFIG_MQTT_RX_MAXLEN=5000 -DCONFIG_MQTT_SUBTOPIC_MAXNUM=65535 -DDM_ENABLED -DFORCE_SSL_VERIFY -DHTTP_COMM_ENABLED -DIOTX_NET_INIT_WITH_PK_EXT -DMQTT_COMM_ENABLED -DMQTT_DIRECT -DOTA_ENABLED -DOTA_SIGNAL_CHANNEL=1 -DSDK_ENHANCE -DSERVICE_OTA_ENABLED -DSUPPORT_TLS -DTEST_HTTP_DAILY -DWITH_MEM_STATS=0 -DWITH_MQTT_DYNBUF=1 -D_PLATFORM_IS_LINUX_ -D__UBUNTU_SDK_DEMO__ -Os -Wall -Werror -Werror -g3 -rdynamic
COMP_LIB := libiot_sdk.a
COMP_LIB_COMPONENTS := src/infra/log src/infra/system src/infra/utils src/protocol/alcs src/protocol/http src/protocol/mqtt src/sdk-impl src/services/linkkit/cm src/services/linkkit/dm src/services/uOTA
CONFIG_VENDOR := ubuntu
CROSS_CANDIDATES := AR CC CXX LD OBJCOPY STRIP
CROSS_PREFIX := 
CXX := g++
EXPORT_DIR := include
IMPORT_DIR := prebuilt
INSTALL_DIR := /mnt/hgfs/F/YQ/srcs/iotx-sdk-c/.O/usr
INSTALL_LIB_DIR := /mnt/hgfs/F/YQ/srcs/iotx-sdk-c/.O/usr/lib
KERNEL_DIR := 
LD := ld
LDFLAGS := -lpthread -lrt
MAKE_ENV_VARS := 
NOEXEC_CMAKE_DIRS := src/services/linkkit/dm tests
OBJCOPY := objcopy
PACKAGE_DIR := /mnt/hgfs/F/YQ/srcs/iotx-sdk-c/packages
RULE_DIR := /mnt/hgfs/F/YQ/srcs/iotx-sdk-c/build-rules
STRIP := strip
SYSROOT_INC := /mnt/hgfs/F/YQ/srcs/iotx-sdk-c/.O/usr/include
TOP_DIR := /mnt/hgfs/F/YQ/srcs/iotx-sdk-c
WIN32_CMAKE_SKIP := coap-example linkkit_tsl_convert
COMP_LIB_FILES :=  libiot_utils.a  libiot_log.a  libiot_system.a  libsdk_impl.a  libiot_mqtt.a  libiot_ota.a  libiot_http.a  libiot_alcs.a  libiot_cm.a  libiot_dm.a

include $(RULE_DIR)/settings.mk
include $(CONFIG_TPL)

all:

DEPENDS             := src/ref-impl/hal
DEPENDS             += src/ref-impl/tls

HDR_REFS            += src

LDFLAGS             := -Bstatic
LDFLAGS             += -liot_sdk
LDFLAGS             += -liot_hal
CFLAGS              := $(filter-out -ansi,$(CFLAGS))
ifeq (,$(filter -DIOTX_WITHOUT_TLS,$(CFLAGS)))
LDFLAGS             += -liot_tls
endif
ifneq (,$(filter -D_PLATFORM_IS_WINDOWS_,$(CFLAGS)))
LDFLAGS             += -lws2_32
CFLAGS              := $(filter-out -DCOAP_COMM_ENABLED,$(CFLAGS))
endif

ifneq (,$(filter -DMQTT_COMM_ENABLED,$(CFLAGS)))
TARGET                          += mqtt-example mqtt_rrpc-example mqtt_multi_thread-example
SRCS_mqtt-example               := mqtt/mqtt-example.c
SRCS_mqtt_rrpc-example          := mqtt/mqtt_rrpc-example.c
SRCS_mqtt_multi_thread-example  := mqtt/mqtt_multi_thread-example.c

    ifneq (,$(filter -DOTA_ENABLED,$(CFLAGS)))
    ifneq (,$(filter -DOTA_SIGNAL_CHANNEL=1,$(CFLAGS)))
    TARGET                      += ota_mqtt-example
    SRCS_ota_mqtt-example       := uOTA/ota_mqtt-example.c
    endif
    endif

    ifneq (,$(filter -DOTA_ENABLED,$(CFLAGS)))
    TARGET                      += uota_app-example
    SRCS_uota_app-example       := uOTA/uota_app-example.c
    endif

    ifneq (,$(filter -DMQTT_SHADOW,$(CFLAGS)))
    TARGET                      += shadow-example
    SRCS_shadow-example         := device-shadow/shadow-example.c
    endif

    ifneq (,$(filter -DSUPPORT_ITLS,$(CFLAGS)))

    LDFLAGS += \
        -litls \
        -lid2client \
        -lkm \
        -lplat_gen \
        -lalicrypto \
        -lmbedcrypto \

    endif

endif

ifneq (,$(filter -DCOAP_COMM_ENABLED,$(CFLAGS)))
TARGET              += coap-example

SRCS_coap-example   := coap/coap-example.c
SRCS                += coap/coap-example.c

    ifneq (,$(filter -DOTA_ENABLED,$(CFLAGS)))
    ifneq (,$(filter -DOTA_SIGNAL_CHANNEL=2,$(CFLAGS)))
    TARGET                  += ota_coap-example
    SRCS_ota_coap-example   := uOTA/ota_coap-example.c
    endif
    endif
endif

ifneq (,$(filter -DHTTP_COMM_ENABLED,$(CFLAGS)))
TARGET              += http-example
SRCS_http-example   := http/http-example.c
endif

ifneq (,$(filter -DHTTP2_COMM_ENABLED,$(CFLAGS)))
TARGET              += http2-example
SRCS_http2-example  := http2/http2-example.c
endif

ifneq (,$(filter -DSUBDEVICE_ENABLED,$(CFLAGS)))
TARGET                  += subdev-example
SRCS_subdev-example     += subdev/subdev-example.c \
                           subdev/subdev_example_api.c
endif

ifneq (,$(filter -DSDK_ENHANCE,$(CFLAGS)))

    ifneq (,$(filter -DCONFIG_DM_DEVTYPE_SINGLE,$(CFLAGS)))
    TARGET                          += linkkit-example-solo
    SRCS_linkkit-example-solo       := linkkit/linkkit_example_solo.c
    endif
    
    ifneq (,$(filter -DCONFIG_DM_DEVTYPE_GATEWAY,$(CFLAGS)))
    TARGET                          += linkkit-example-gw
    SRCS_linkkit-example-gw         += linkkit/linkkit_example_gateway.c \
                                       linkkit/light.c \
                                       linkkit/cJSON.c
    endif

TARGET += linkkit-example-sched
SRCS_linkkit-example-sched = linkkit/linkkit_example_sched.c

endif

env:
	@echo ""
	@printf -- "-----------------------------------------------------------------\n"
	@$(foreach var,$(SHOW_ENV_VARS),$(call Dump_Var,$(var)))
	@printf -- "-----------------------------------------------------------------\n"
	@echo ""

include $(RULE_DIR)/rules.mk
